#!/bin/bash

WINE_CMD="deepin-wine"
BOTTLE="$HOME/.deepinwine/CMBChina"

_SetRegistryValue()
{
    env WINEPREFIX="$BOTTLE" $WINE_CMD reg ADD "$1" /v "$2" /t $3 /d "$4" /f
}

_DeleteRegistryValue()
{
    env WINEPREFIX="$BOTTLE" $WINE_CMD reg DELETE "$1" /v "$2" /f
}

_SetFontReplacements()
{
#    _DeleteRegistryValue 'HKCU\Software\Wine\\Fonts\Replacements' "$1"
    _SetRegistryValue 'HKCU\Software\Wine\\Fonts\Replacements' "$1" REG_MULTI_SZ "$2"
}

if [ -f "$1/user.reg" ]; then
    BOTTLE="$1"
fi

env WINEPREFIX="$BOTTLE" /usr/lib/i386-linux-gnu/deepin-wine/wineserver -k
env WINEPREFIX="$BOTTLE" $WINE_CMD regedit &

_SetFontReplacements "@MS UI Gothic" "@Ume UI Gothic"
_SetFontReplacements "Arial" "MS Sans Serif"
_SetFontReplacements "Arial Unicode MS" "Droid Sans Fallback"
_SetFontReplacements "Batang" "UnBatang"
_SetFontReplacements "DFKai-SB" "Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0"
_SetFontReplacements "Dotum" "UnDotum"
_SetFontReplacements "FangSong" "Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0"
_SetFontReplacements "Gulim" "UnDotum"
_SetFontReplacements "KaiTi" "Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0"
_SetFontReplacements "Lucida Console" "MS Sans Serif"
_SetFontReplacements "Microsoft JhengHei" "Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0"
_SetFontReplacements "Microsoft YaHei" "Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0"
_SetFontReplacements "MingLiU" "Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0"
_SetFontReplacements "MS Gothic" "Ume Gothic"
_SetFontReplacements "MS Mincho" "Ume Mincho"
_SetFontReplacements "MS PGothic" "Ume P Gothic"
_SetFontReplacements "MS PMincho" "Ume P Mincho"
_SetFontReplacements "MS UI Gothic" "Ume UI Gothic"
_SetFontReplacements "NSimSun" "Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0"
_SetFontReplacements "PMingLiU" "Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0"
_SetFontReplacements "SimHei" "Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0"
_SetFontReplacements "SimKai" "Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0"
_SetFontReplacements "SimSun" "Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0"
_SetFontReplacements '微软雅黑' 'Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0'
_SetFontReplacements '楷体_GB2312' 'Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0'
_SetFontReplacements '黑体' 'Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0'
_SetFontReplacements '新細明體' 'Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0'
_SetFontReplacements 'ＭＳＰゴシック' 'Ume P Gothic'
_SetFontReplacements '新宋体' 'Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0'
_SetFontReplacements '仿宋' 'Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0'
_SetFontReplacements '仿宋_GB2312' 'Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0'
_SetFontReplacements '隶书' 'Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0'
_SetFontReplacements '楷体' 'Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0'
_SetFontReplacements '宋体' 'Source Han Sans SC Regular\0Noto Sans CJK SC Regular\0WenQuanYi Micro Hei\0'
